package project13;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Fruit b;
        System.out.println("输入要创建的类：");
        String a=sc.next();
        b=gardener.getfruit(a);
    }
}
interface Fruit
{

}
class apple implements Fruit
{
    public apple() {
        System.out.println("创建了一个苹果类的对象");
    }
}
class banana implements Fruit
{
    public banana() {
        System.out.println("创建了一个香蕉类的对象");
    }
}
class grape implements Fruit
{
    public grape() {System.out.println("生成了一个葡萄类的对象");}
}
class gardener
{
    public static Fruit getfruit(String a)
    {
        if(a.equals("apple"))
        {
            return new apple();
        }
        else if(a.equals("banana"))
            return new banana();
        else if(a.equals("grape"))
            return new grape();
        else
        {
            System.out.println("没有该对象");
            return null;
        }
    }
}
